<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        .login{display:block}
        .user{display:none}
    </style>
</head>
<body>
    <h3>这是首页</h3>

    <p class="login">
        <a href="./login.html">登录</a>
        <a href="./register.html">注册</a>
    </p>

    <p class="user">
        欢迎珍贵的<span>xxx</span>访问本网站
        <em class="q">退出</em>
    </p>


    <a href="./cart.html">去购物车</a>
</body>
<script src="./js/jquery.js"></script>
<script>
    const token = sessionStorage.getItem("isLogin") ? JSON.parse(sessionStorage.getItem("isLogin")) : {};


    if(token.code === "OK"){
        $(".login").hide();
        $(".user").show();
        $(".user").children("span").html(token.name)
    }else{
        $(".login").show();
        $(".user").hide();
    }

    $(".q").click(function(){
        sessionStorage.removeItem("isLogin");
        $(".login").show();
        $(".user").hide();
    })

</script>
</html>